package com.wcfsy.wechat.wx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wcfsy.wechat.wx.entity.WechatUserInfo;
import com.wcfsy.wechat.wx.pagination.IPage;
import com.wcfsy.wechat.wx.pagination.impl.Page;
import com.wcfsy.wechat.wx.sys.dao.UserRegisterInfoDao;
import com.wcfsy.wechat.wx.util.StringUtil;

@Controller
@RequestMapping("/cms/register")
public class UserRegisterController {

	@Resource
	private UserRegisterInfoDao userRegisterInfoDao;

	@RequestMapping("/view/page")
	public String page() {
		return "register/register_list";
	}

	@RequestMapping("/view")
	@ResponseBody
	public IPage<WechatUserInfo> getOnAdConfigs(
			String mobile,int page, 
			int rows,String recommendedCode,String email,String userName,String memberName) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if(StringUtils.isNotEmpty(userName)){
			paramMap.put("userName", StringUtil.encode(userName));
		}
		if(StringUtils.isNotEmpty(email)){
			paramMap.put("email", email);
		}
		if(StringUtils.isNotEmpty(mobile)){
			paramMap.put("mobile", mobile);
		}
		if(StringUtils.isNotEmpty(memberName)){
			paramMap.put("memberName", memberName);
		}
		
		paramMap.put("index", page);
		paramMap.put("size", rows);
		paramMap.put("limit", "limit");
		IPage<WechatUserInfo> page1 =new Page<WechatUserInfo>(
				this.userRegisterInfoDao.findByParam(paramMap),
				this.userRegisterInfoDao.count(paramMap), page, rows);
		List<WechatUserInfo> list = page1.getData();
		for (int i = 0; i < list.size(); i++) {
			if(StringUtils.isNotEmpty(page1.getData().get(i).getNickname())){
				page1.getData().get(i).setNickname(StringUtil.decode(page1.getData().get(i).getNickname()));
			}
		}
		return  page1;
	}
}
